<?php

class Userv2_model extends Base_Model
{
    const TABLE = 'user_v2';

    public function __construct()
    {
        $this->load->database();
    }

    /**
     * 创建会员
     *
     * @param $data
     * @return bool|int
     */
    public function createUser($data)
    {
        if($this->db->insert(self::TABLE, $data)){
            return $this->db->insert_id();
        }else{
            return false;
        }
    }

    /**
     * 修改会员
     *
     * @param $data
     * @param $where
     * @return CI_DB_active_record|CI_DB_result
     */
    public function editUser($data, $where)
    {
        return $this->db->update(self::TABLE, $data, $where);
    }

    /**
     * 获取userv2信息
     *
     * @param $where
     * @return mixed
     */
    function getUserv2($where, $data = '*')
    {
        $query = $this->db->select($data)->get_where(self::TABLE, $where);
        return $query->row_array();
    }

    /**
     * 检查用户
     *
     * @param $mobile
     * @param $email
     * @return array
     */
    function checkUser($email, $uType)
    {
        $query = $this->db->select('uid, utype, userToken, active, telActive')
                          ->from(self::TABLE)
                          ->where('(telNum ="' .$email.'" or userId = "'.$email.'")')
                          ->where(array('utype' => $uType));

        return $query->get()->row_array();

    }

    /**
     * 获取user信息
     *
     * @param $where
     * @return array
     */
    function getUser($where)
    {
        return $this->db->get_where(self::TABLE, $where)->row_array();
    }

}